home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Bitmap / Sources / BmpFrame.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  5.6 KB  |  199 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BmpFrame.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef BMPFRAME_H
  14. #include "BmpFrame.h"
  15. #endif
  16.  
  17. #ifndef BMPFACET_H
  18. #include "BmpFacet.h"
  19. #endif
  20.  
  21. #ifndef BMPPART_H
  22. #include "BmpPart.h"
  23. #endif
  24.  
  25. #ifndef BMPSEL_H
  26. #include "BmpSel.h"
  27. #endif
  28.  
  29. // ----- Graphic Includes -----
  30.  
  31. #ifndef FWGRUTIL_H
  32. #include "FWGrUtil.h"
  33. #endif
  34.  
  35. // ----- OpenDoc Includes -----
  36.  
  37. #ifndef _MENUBAR_
  38. #include <MenuBar.h>
  39. #endif
  40.  
  41. #ifndef _SHAPE_
  42. #include "Shape.h"
  43. #endif
  44.  
  45. // ----- Macintosh Includes -----
  46.  
  47. #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
  48. #include <math routines.h>
  49. #endif
  50.  
  51. #pragma segment bitmappart
  52.  
  53. //========================================================================================
  54. //    •• class CBitmapFrame
  55. //========================================================================================
  56.  
  57. //----------------------------------------------------------------------------------------
  58. //    • CBitmapFrame::CBitmapFrame
  59. //----------------------------------------------------------------------------------------
  60.  
  61. CBitmapFrame::CBitmapFrame() :
  62.     fBitmapPart(NULL)
  63. {
  64. }
  65.  
  66. //----------------------------------------------------------------------------------------
  67. //    • CBitmapFrame::~CBitmapFrame
  68. //----------------------------------------------------------------------------------------
  69.  
  70. CBitmapFrame::~CBitmapFrame()
  71. {
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    • CBitmapFrame::InitBitmapFrame
  76. //----------------------------------------------------------------------------------------
  77.  
  78. void CBitmapFrame::InitBitmapFrame(XMPFrame* xmpFrame, CBitmapPart* bitmapPart)
  79. {
  80.     this->InitFrame(xmpFrame, bitmapPart);
  81.     
  82.     fBitmapPart = bitmapPart;
  83.  
  84.     AddToFocusSet(bitmapPart->GetKeyFocusToken());
  85.     AddToFocusSet(bitmapPart->GetMenuFocusToken());
  86.     AddToFocusSet(bitmapPart->GetSelectionFocusToken());
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    • CBitmapFrame::NewFacet
  91. //----------------------------------------------------------------------------------------
  92.  
  93. FW_CFacet* CBitmapFrame::NewFacet(XMPFacet* xmpFacet)
  94. {
  95.     CBitmapFacet* facet = new CBitmapFacet;
  96.     facet->InitBitmapFacet(xmpFacet, fBitmapPart);
  97.  
  98.     return facet;
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    • CBitmapFrame::DoAdjustMenus
  103. //----------------------------------------------------------------------------------------
  104.  
  105. void CBitmapFrame::DoAdjustMenus(XMPMenuBar* menuBar)
  106. {
  107.     FW_CFrame::DoAdjustMenus(menuBar);
  108.     
  109.     FW_CPoint ratio = GetZoomRatio();
  110.     
  111.     menuBar->EnableAndCheckCommand(cHalfSize, !IsRoot(), (ratio.x == fl(0.5) && ratio.y == fl(0.5)));
  112.     menuBar->EnableAndCheckCommand(cRealSize, !IsRoot(), (ratio.x == ff(1) && ratio.y == ff(1)));
  113.     menuBar->EnableAndCheckCommand(cDoubleSize, !IsRoot(), (ratio.x == ff(2) && ratio.y == ff(2)));
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    • CBitmapFrame::DoMenu
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_Boolean CBitmapFrame::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID commandID)
  121. {
  122.     FW_Boolean result = TRUE;
  123.  
  124.     switch (commandID)
  125.     {
  126.         case cHalfSize:    
  127.         case cRealSize:        
  128.         case cDoubleSize:    
  129.             AdjustBitmapSize(commandID);
  130.             break;
  131.             
  132.         default:
  133.             result = FW_CFrame::DoMenuEvent(menuBar, commandID);
  134.     }
  135.  
  136.     return result;
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    • CBitmapFrame::AdjustBitmapSize
  141. //----------------------------------------------------------------------------------------
  142.  
  143. void CBitmapFrame::AdjustBitmapSize(XMPCommandID commandID)
  144. {
  145.     FW_CRect bitmapRect, frameRect;
  146.     fBitmapPart->CalcBitmapRect(&bitmapRect, commandID);
  147.     
  148.     GetFrameShapeBounds(&frameRect);
  149.     frameRect.Place(0, 0);
  150.     
  151.     if (frameRect != bitmapRect)
  152.     {
  153.         XMPShape* oldFrameShape = ::NewXMPShape();
  154.         GetFrameShape(oldFrameShape);
  155.         XMPShape* returnedShape = RequestFrameShape(::NewXMPShape(bitmapRect));
  156.         if (!returnedShape->IsSameAs(oldFrameShape))
  157.         {
  158.             UpdateUsedAndActiveShapes();
  159.             oldFrameShape->Union(returnedShape);
  160.             InvalidateAllFacets(NULL, oldFrameShape);
  161.         }
  162.         delete oldFrameShape;
  163.     }
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    • CBitmapFrame::FocusStateChanged
  168. //----------------------------------------------------------------------------------------
  169.  
  170. void CBitmapFrame::FocusStateChanged(XMPTypeToken focus, FW_Boolean newState)
  171. {    
  172.     FW_CFrame::FocusStateChanged(focus, newState);
  173.  
  174.     if (focus == GetPart()->GetSelectionFocusToken())
  175.     {
  176.         CBitmapSelection *bitmapSelection = fBitmapPart->GetBitmapSelection();
  177.         if (!bitmapSelection->IsEmpty())
  178.             bitmapSelection->DrawAnts(this);
  179.     }
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    • CBitmapFrame::GetZoomRatio
  184. //----------------------------------------------------------------------------------------
  185.  
  186. FW_CPoint CBitmapFrame::GetZoomRatio() const
  187. {
  188.     FW_CRect frameRect;
  189.     GetFrameShapeBounds(&frameRect);
  190.     
  191.     FW_CBitmapShape bitmapShape = fBitmapPart->GetBitmapShape();
  192.     short width, height, rowBytes, pixelSize;
  193.     bitmapShape->GetBitmapInfo(width, height, rowBytes, pixelSize);
  194.     
  195.     FW_CPoint ratio((frameRect.right - frameRect.left) / width, 
  196.                     (frameRect.bottom - frameRect.top) / height);
  197.     
  198.     return ratio;
  199. }